package models;

import constants.MessageType;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.util.Log;
import android.util.Pair;

/**
 * 
 * @author Merete, Mirna, Esben, Knut og Stian
 * 
 */
public class Mushroom extends PhysicalObject {
	private int value;
	private static final String TAG = Mushroom.class.getSimpleName();

	public Mushroom(Bitmap bitmap, double x, double y, int width, int height, int frameCount) {
		super(bitmap, x, y, width, height, 1);

		// TODO Auto-generated constructor stub
		this.value = -1;
		
		//setup rects
		srcRect = new Rect(0, 0, spriteWidth, spriteHeight);
		destRect = new Rect(0, 0, spriteWidth, spriteHeight);
	}

	/**
	 * value represents the points given if the pig takes this mushroom
	 * 
	 * @return value
	 */
	public int getValue() {
		return value;
	}

	/**
	 *
	 */
	public void setValue(int value) {
		this.value = value;
	}

	@Override
	public void update() {
		x = x + motion.getHorizontalVelocity();
		y = y + motion.getVerticalVelocity();

		// move rectangle
		rect.set((int) x, (int) y, spriteWidth + (int) x, spriteHeight
				+ (int) y);
		
		//check if outside the screen
		if(active) {
			if(x <= 0 - spriteWidth) {
				active = false;
				setChanged();
				pair = new Pair<PhysicalObject, MessageType>(this,MessageType.OUTSIDEVIEW);
				notifyObservers(pair);		
			}
			
			destRect.set((int)x, (int)y, ((int)x+spriteWidth), ((int)y+spriteHeight));
			
		}

	}

	@Override
	public void draw(Canvas canvas) {
		canvas.drawBitmap(bitmap, srcRect, destRect, null);

	}


}
